package model;

import java.util.Date;

public class WorkoutPlan {
	private User user;
	private Exercise[] exercises;
	private int[] sets;
	private double[] weights;
	private int breakTime;
	private Date date;
	private int duration;
	/**
	 * 0 Kraftausdauer, 1 Hypertrophie, 2 Maximalkraft
	 */
	private Purpose purpose;
	private String dummy = "Dummy ";

	public WorkoutPlan(User user, int duration, int sets, Purpose purpose, Date date) {
		this.user = user;
		this.exercises = new Exercise[13];
		this.sets = new int[13];
		this.weights = new double[13];
		for (int i = 0; i < exercises.length; i++) {
			addDummyAt(i);
			this.sets[i] = sets;
			this.weights[i] = 0;
		}
		this.date = date;
		this.duration = duration;
		this.setPurpose(purpose);
	}

	private boolean validatePosition(int pos) {
		if (pos >= 0 && pos < exercises.length) {
			return true;
		} else {
			return false;
		}
	}

	public void addExercise(Exercise exercise, int pos) {
		if (validatePosition(pos)) {
			this.exercises[pos] = exercise;
		}
	}

	public void removeExercise(Exercise exercise) {
		for (int i = 0; i < exercises.length; i++) {
			if (exercise == exercises[i]) {
				removeExercise(i);
			}
		}
	}

	public void switchExercises(int pos1, int pos2) {
		if (validatePosition(pos1) && validatePosition(pos2)) {
			Exercise ex = exercises[pos1];
			this.exercises[pos1] = exercises[pos2];
			this.exercises[pos2] = ex;
		}
	}

	public void removeExercise(int pos) {
		if (validatePosition(pos)) {
			this.exercises[pos] = new Exercise(dummy, null);
		}
	}

	public Exercise getExerciseAt(int pos) {
		if (validatePosition(pos)) {
			return exercises[pos];
		} else {
			return null;
		}
	}

	public void addDummyAt(int pos) {
		if (validatePosition(pos)) {
			this.exercises[pos] = new Exercise(dummy, null);
		}
	}

	public User getUser() {
		return user;
	}

	public void setUser(User user) {
		this.user = user;
	}

	public int[] getSets() {
		return sets;
	}

	public void setSets(int[] sets) {
		this.sets = sets;
	}

	public double[] getWeights() {
		return weights;
	}

	public void setWeights(double[] weights) {
		this.weights = weights;
	}

	public int getBreakTime() {
		return breakTime;
	}

	public void setBreakTime(int breakTime) {
		this.breakTime = breakTime;
	}

	public Date getDate() {
		return date;
	}

	public void setDate(Date date) {
		this.date = date;
	}

	public int getDuration() {
		return duration;
	}

	public void setDuration(int duration) {
		this.duration = duration;
	}

	public Purpose getPurpose() {
		return purpose;
	}

	public void setPurpose(Purpose purpose) {
		this.purpose = purpose;
	}

	public String getDummy() {
		return dummy;
	}
}
